/**
 *  按钮权限 自定义指令
 */
import Vue from 'vue'
import store from '@/store'

const has = Vue.directive('has', {
  inserted: function (el, binding) {
    // 获取按钮权限
    if (!Vue.prototype.$_has(binding.value)) {
      el.parentNode.removeChild(el)
    }
  }
})
Vue.prototype.$_has = function (value) {
  let isExit = false
  let buttonpermsStr = store.getters.permissions
  if (buttonpermsStr === undefined || buttonpermsStr === null) {
    return false
  }
  for (let i = 0; i < buttonpermsStr.length; i++) {
    if (value === buttonpermsStr[i]) {
      isExit = true
      break
    }
  }
  return isExit
}
export {has}
